"use strict";(function(){function e(e){function a(e,a,n,p){f-- >0&&!a&&599!=p?d.size>z?t(n,J[n],N[n]):i():c(-1,e)}function n(){for(var e,a=0;a<O.size;)e=Math.min(z,O.size-a),J.push(e),N.push(O.slice(a,a+e)),a+=e
    t(0,J[0],N[0])}function t(e,n,i){var l=new FormData
    l.append("size",n)
    var f
    0==e?(l.append("dir",u),l.append("name",d.name),f=x):(l.append("id",s),l.append("uploadId",r),l.append("partNumber",e+1),f=S),l.append("content",i,O.name),o(f,l,function(o){var u=o.status,f=o.statusText||""
        if(200==u&&"OK"==f){var m=JSON.parse(o.responseText)
            y[e]=m.eTag,T+=n
            var v=Math.ceil(T/d.size*100)
            if(c(v),0==e){s=m.id,r=m.uploadId
                for(var x=1;x<N.length;x++)t(x,J[x],N[x])}T>=O.size&&(O=null,i=l=null,p())}else a(JSON.parse(o.responseText),0,e,u)})}function p(){for(var e=[],n=0;n<y.length;n++)e[n]={partNumber:n+1,eTag:y[n]}
    e=btoa(JSON.stringify(e))
    var t=new FormData
    t.append("id",s),t.append("uploadId",r),t.append("parts",e),o(h,t,function(e){var n=e.status,t=e.statusText||""
        200==n&&"OK"==t?c(100,JSON.parse(e.responseText)):a(JSON.parse(e.responseText),1,"",n)})}function i(){var e=new FormData
    e.append("dir",u),e.append("name",d.name),e.append("size",d.size),e.append("content",d)
    var n=v
    o(n,e,function(e){var n=e.status,t=e.statusText||""
        200==n&&"OK"==t?c(100,JSON.parse(e.responseText)):a(JSON.parse(e.responseText),"","",n)})}function o(e,a,n){var t=new XMLHttpRequest
    t.open("POST",e),t.setRequestHeader("Authorization",l),t.setRequestHeader("UserAgent","ALIMEDIASDK_JSSDK"),t.onload=function(e){n(t)},t.send(a)}var s,r,d=e.file,u=e.dir||"",l=e.token,c=e.callback||function(){},f=e.retries||0,m=e.maxSize||0,v="http://upload.media.aliyun.com/api/proxy/upload",x="http://upload.media.aliyun.com/api/proxy/blockInit",S="http://upload.media.aliyun.com/api/proxy/blockUpload",h="http://upload.media.aliyun.com/api/proxy/blockComplete",z=4194304,T=0,O=d,y=[],J=[],N=[]
    return d&&l?m&&d.size>m?void c(-1,"文件大小不能超过"+m):void(d.size>z?n():i()):void c(-1,"上传文件参数必须配置file以及token")}this.uploadJSSDK=e}).call(this)
